<template>
  <nav class="navbar">
    <div class="leftMenu">
      <img src="../assets/logo.png" />
    </div>
    <div class="rightMenu">
      <span>{{ username }}({{ role }})</span>
      <img class="ml-5" style="height: 30px" src="@/assets/gita.gif" alt="" />
      <span class="line"></span>
      <span @click="logout" class="logout">退出登录</span>
      <div class="lang rel">
        <span class="text abs">cn</span>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { useRouter } from "vue-router";
import { useStore } from "@/store/useStore";
import { storeToRefs } from "pinia";
import { computed } from "vue";
const router = useRouter();
const store = useStore();
const { username, type } = storeToRefs(store); 
//根据type 判断角色
const role = computed(() => { 
  if (type.value == 1) {
    return "管理员";
  } else if (type.value == 2) {
    return "用户";
  } 
}); 
const logout = () => {
  store.$patch((state) => {
    state.username = "";
    state.token = "";
  });
  router.push("/login");
};
</script>

<style scoped lang="less">
.navbar {
  display: flex;
  height: 50px;
  justify-content: space-between;
  align-items: center;
  background: #fff;
}

.leftMenu {
  height: 100%;
  display: flex;
  align-items: center;

  > img {
    height: 35px;
    width: auto;
    margin-left: 15px;
  }
}

.rightMenu {
  display: flex;
  align-items: center;
  // padding-right: 50px;
  .lang {
    width: 0;
    height: 0;
    border: 25px solid #014ff7;
    border-bottom-color: transparent;
    border-left-color: transparent;
    .text {
      font-size: 20px;
      top: -24px;
      left: 0;
      color: #fff;
    }
  }

  .flag {
    height: 30px;
    width: auto;
    margin-right: 10px;
  }
  .logout {
    color: #409eff;
    text-decoration: underline;
    cursor: pointer;
    margin-left: 10px;
  }

  .line {
    height: 16px;
    width: 1px;
    background: rgba(90, 88, 88, 0.36);
    margin-left: 10px;
  }
  .icon-screenfull {
    font-size: 22px;
    margin: 0 10px;
  }
  .langSelect {
    height: 50px;
    width: auto;
  }
}
</style>
